package com.xuan.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xuan.mapper.DeptMapper;
import com.xuan.pojo.Dept;
import com.xuan.pojo.Dto.PageQueryDto;
import com.xuan.result.PageQueryResult;
import com.xuan.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public List<Dept> selectAll() {
        return deptMapper.selectAll();
    }

    @Override
    public PageQueryResult<Dept> pageQuery(PageQueryDto pageQueryDto) {
        PageHelper.startPage(pageQueryDto.getPageNum(), pageQueryDto.getPageSize());
        Page<Dept> page = deptMapper.pageQuery(pageQueryDto);
        long total = page.getTotal();
        List<Dept> rows = page.getResult();
        return new PageQueryResult<>(total, rows);
    }
}
